<?php

/**
 * MskuPrepDetail.
 *
 * PHP version 8.3
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * The Selling Partner API for FBA inbound operations.
 *
 * The Selling Partner API for Fulfillment By Amazon (FBA) Inbound. The FBA Inbound API enables building inbound workflows to create, manage, and send shipments into Amazon's fulfillment network. The API has interoperability with the Send-to-Amazon user interface.
 *
 * The version of the OpenAPI document: 2024-03-20
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.9.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace SpApi\Model\fulfillment\inbound\v2024_03_20;

use SpApi\Model\ModelInterface;
use SpApi\ObjectSerializer;

/**
 * MskuPrepDetail Class Doc Comment.
 *
 * @category Class
 *
 * @description An MSKU and its related prep details.
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @implements \ArrayAccess<string, mixed>
 */
class MskuPrepDetail implements ModelInterface, \ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

    /**
     * The original name of the model.
     */
    protected static string $openAPIModelName = 'MskuPrepDetail';

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static array $openAPITypes = [
        'all_owners_constraint' => '\SpApi\Model\fulfillment\inbound\v2024_03_20\AllOwnersConstraint',
        'label_owner_constraint' => '\SpApi\Model\fulfillment\inbound\v2024_03_20\OwnerConstraint',
        'msku' => 'string',
        'prep_category' => '\SpApi\Model\fulfillment\inbound\v2024_03_20\PrepCategory',
        'prep_owner_constraint' => '\SpApi\Model\fulfillment\inbound\v2024_03_20\OwnerConstraint',
        'prep_types' => '\SpApi\Model\fulfillment\inbound\v2024_03_20\PrepType[]'];

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @var string[]
     *
     * @phpstan-var array<string, string|null>
     *
     * @psalm-var array<string, string|null>
     */
    protected static array $openAPIFormats = [
        'all_owners_constraint' => null,
        'label_owner_constraint' => null,
        'msku' => null,
        'prep_category' => null,
        'prep_owner_constraint' => null,
        'prep_types' => null];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'all_owners_constraint' => true,
        'label_owner_constraint' => true,
        'msku' => false,
        'prep_category' => false,
        'prep_owner_constraint' => true,
        'prep_types' => false,
    ];

    /**
     * If a nullable field gets set to null, insert it here.
     *
     * @var bool[]
     */
    protected array $openAPINullablesSetToNull = [];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @var string[]
     */
    protected static array $attributeMap = [
        'all_owners_constraint' => 'allOwnersConstraint',
        'label_owner_constraint' => 'labelOwnerConstraint',
        'msku' => 'msku',
        'prep_category' => 'prepCategory',
        'prep_owner_constraint' => 'prepOwnerConstraint',
        'prep_types' => 'prepTypes',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static array $setters = [
        'all_owners_constraint' => 'setAllOwnersConstraint',
        'label_owner_constraint' => 'setLabelOwnerConstraint',
        'msku' => 'setMsku',
        'prep_category' => 'setPrepCategory',
        'prep_owner_constraint' => 'setPrepOwnerConstraint',
        'prep_types' => 'setPrepTypes',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static array $getters = [
        'all_owners_constraint' => 'getAllOwnersConstraint',
        'label_owner_constraint' => 'getLabelOwnerConstraint',
        'msku' => 'getMsku',
        'prep_category' => 'getPrepCategory',
        'prep_owner_constraint' => 'getPrepOwnerConstraint',
        'prep_types' => 'getPrepTypes',
    ];

    /**
     * Associative array for storing property values.
     */
    protected array $container = [];

    /**
     * Constructor.
     *
     * @param null|array $data Associated array of property values
     *                         initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('all_owners_constraint', $data ?? [], null);
        $this->setIfExists('label_owner_constraint', $data ?? [], null);
        $this->setIfExists('msku', $data ?? [], null);
        $this->setIfExists('prep_category', $data ?? [], null);
        $this->setIfExists('prep_owner_constraint', $data ?? [], null);
        $this->setIfExists('prep_types', $data ?? [], null);
    }

    /**
     * Gets the string presentation of the object.
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

    /**
     * Array of property to type mappings. Used for (de)serialization.
     */
    public static function openAPITypes(): array
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization.
     */
    public static function openAPIFormats(): array
    {
        return self::$openAPIFormats;
    }

    /**
     * Checks if a property is nullable.
     */
    public static function isNullable(string $property): bool
    {
        return self::openAPINullables()[$property] ?? false;
    }

    /**
     * Checks if a nullable property is set to null.
     */
    public function isNullableSetToNull(string $property): bool
    {
        return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     */
    public static function attributeMap(): array
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     */
    public static function setters(): array
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests).
     */
    public static function getters(): array
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     */
    public function getModelName(): string
    {
        return self::$openAPIModelName;
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties(): array
    {
        $invalidProperties = [];

        if (null === $this->container['msku']) {
            $invalidProperties[] = "'msku' can't be null";
        }
        if (mb_strlen($this->container['msku']) > 40) {
            $invalidProperties[] = "invalid value for 'msku', the character length must be smaller than or equal to 40.";
        }

        if (mb_strlen($this->container['msku']) < 1) {
            $invalidProperties[] = "invalid value for 'msku', the character length must be bigger than or equal to 1.";
        }

        if (null === $this->container['prep_category']) {
            $invalidProperties[] = "'prep_category' can't be null";
        }
        if (null === $this->container['prep_types']) {
            $invalidProperties[] = "'prep_types' can't be null";
        }

        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed.
     *
     * @return bool True if all properties are valid
     */
    public function valid(): bool
    {
        return 0 === count($this->listInvalidProperties());
    }

    /**
     * Gets all_owners_constraint.
     */
    public function getAllOwnersConstraint(): ?string
    {
        return $this->container['all_owners_constraint'];
    }

    /**
     * Sets all_owners_constraint.
     *
     * @param null|string $all_owners_constraint all_owners_constraint
     */
    public function setAllOwnersConstraint(?string $all_owners_constraint): self
    {
        if (is_null($all_owners_constraint)) {
            array_push($this->openAPINullablesSetToNull, 'all_owners_constraint');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('all_owners_constraint', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['all_owners_constraint'] = $all_owners_constraint;

        return $this;
    }

    /**
     * Gets label_owner_constraint.
     */
    public function getLabelOwnerConstraint(): ?string
    {
        return $this->container['label_owner_constraint'];
    }

    /**
     * Sets label_owner_constraint.
     *
     * @param null|string $label_owner_constraint label_owner_constraint
     */
    public function setLabelOwnerConstraint(?string $label_owner_constraint): self
    {
        if (is_null($label_owner_constraint)) {
            array_push($this->openAPINullablesSetToNull, 'label_owner_constraint');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('label_owner_constraint', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['label_owner_constraint'] = $label_owner_constraint;

        return $this;
    }

    /**
     * Gets msku.
     */
    public function getMsku(): string
    {
        return $this->container['msku'];
    }

    /**
     * Sets msku.
     *
     * @param string $msku the merchant SKU, a merchant-supplied identifier for a specific SKU
     */
    public function setMsku(string $msku): self
    {
        if (is_null($msku)) {
            throw new \InvalidArgumentException('non-nullable msku cannot be null');
        }
        if (mb_strlen($msku) > 40) {
            throw new \InvalidArgumentException('invalid length for $msku when calling MskuPrepDetail., must be smaller than or equal to 40.');
        }
        if (mb_strlen($msku) < 1) {
            throw new \InvalidArgumentException('invalid length for $msku when calling MskuPrepDetail., must be bigger than or equal to 1.');
        }

        $this->container['msku'] = $msku;

        return $this;
    }

    /**
     * Gets prep_category.
     */
    public function getPrepCategory(): string
    {
        return $this->container['prep_category'];
    }

    /**
     * Sets prep_category.
     *
     * @param string $prep_category prep_category
     */
    public function setPrepCategory(string $prep_category): self
    {
        if (is_null($prep_category)) {
            throw new \InvalidArgumentException('non-nullable prep_category cannot be null');
        }
        $this->container['prep_category'] = $prep_category;

        return $this;
    }

    /**
     * Gets prep_owner_constraint.
     */
    public function getPrepOwnerConstraint(): ?string
    {
        return $this->container['prep_owner_constraint'];
    }

    /**
     * Sets prep_owner_constraint.
     *
     * @param null|string $prep_owner_constraint prep_owner_constraint
     */
    public function setPrepOwnerConstraint(?string $prep_owner_constraint): self
    {
        if (is_null($prep_owner_constraint)) {
            array_push($this->openAPINullablesSetToNull, 'prep_owner_constraint');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('prep_owner_constraint', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['prep_owner_constraint'] = $prep_owner_constraint;

        return $this;
    }

    /**
     * Gets prep_types.
     */
    public function getPrepTypes(): array
    {
        return $this->container['prep_types'];
    }

    /**
     * Sets prep_types.
     *
     * @param array $prep_types a list of preparation types associated with a preparation category
     */
    public function setPrepTypes(array $prep_types): self
    {
        if (is_null($prep_types)) {
            throw new \InvalidArgumentException('non-nullable prep_types cannot be null');
        }
        $this->container['prep_types'] = $prep_types;

        return $this;
    }

    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param int $offset Offset
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param int $offset Offset
     *
     * @return null|mixed
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset): mixed
    {
        return $this->container[$offset] ?? null;
    }

    /**
     * Sets value based on offset.
     *
     * @param null|int $offset Offset
     * @param mixed    $value  Value to be set
     */
    public function offsetSet($offset, mixed $value): void
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param int $offset Offset
     */
    public function offsetUnset($offset): void
    {
        unset($this->container[$offset]);
    }

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     *
     * @see https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     *
     * @return mixed returns data which can be serialized by json_encode(), which is a value
     *               of any type other than a resource
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize(): mixed
    {
        return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets a header-safe presentation of the object.
     */
    public function toHeaderValue(): string
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this));
    }

    /**
     * Array of nullable properties.
     */
    protected static function openAPINullables(): array
    {
        return self::$openAPINullables;
    }

    /**
     * Array of nullable field names deliberately set to null.
     *
     * @return bool[]
     */
    private function getOpenAPINullablesSetToNull(): array
    {
        return $this->openAPINullablesSetToNull;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null.
     *
     * @param bool[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
    }

    /**
     * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
     * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
     * $this->openAPINullablesSetToNull array.
     *
     * @param mixed $defaultValue
     */
    private function setIfExists(string $variableName, array $fields, $defaultValue): void
    {
        if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
            $this->openAPINullablesSetToNull[] = $variableName;
        }

        $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
    }
}
